package com.exam.project.business.controller;

import java.util.List;

import com.exam.common.utils.SecurityUtils;
import com.exam.project.business.dto.UserExamDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.exam.framework.aspectj.lang.annotation.Log;
import com.exam.framework.aspectj.lang.enums.BusinessType;
import com.exam.project.business.domain.UserExam;
import com.exam.project.business.service.IUserExamService;
import com.exam.framework.web.controller.BaseController;
import com.exam.framework.web.domain.AjaxResult;
import com.exam.framework.web.page.TableDataInfo;

/**
 * 学生考试表Controller
 * 
 * @author qiuwenbing
 * @date 2025-04-03
 */
@RestController
@RequestMapping("/business/userexam")
public class UserExamController extends BaseController
{
    @Autowired
    private IUserExamService userExamService;

    /**
     * 查询学生考试表列表
     */
    @PreAuthorize("@ss.hasPermi('business:userexam:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserExam userExam)
    {
        userExam.setUserId(SecurityUtils.getUserId());
        startPage();
        List<UserExamDto> list = userExamService.selectUserExamList(userExam);
        return getDataTable(list);
    }

    @GetMapping("/studentList")
    public TableDataInfo studentList(UserExam userExam)
    {
        startPage();
        List<UserExamDto> list = userExamService.selectUserExamList(userExam);
        return getDataTable(list);
    }

    /**
     * 获取学生考试表详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:userexam:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userExamService.selectUserExamById(id));
    }

    /**
     * 新增学生考试表
     */
    @PreAuthorize("@ss.hasPermi('business:userexam:add')")
    @Log(title = "学生考试表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserExam userExam)
    {
        return toAjax(userExamService.insertUserExam(userExam));
    }

    /**
     * 修改学生考试表
     */
    @PreAuthorize("@ss.hasPermi('business:userexam:edit')")
    @Log(title = "学生考试表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserExam userExam)
    {
        return toAjax(userExamService.updateUserExam(userExam));
    }

    /**
     * 删除学生考试表
     */
    @PreAuthorize("@ss.hasPermi('business:userexam:remove')")
    @Log(title = "学生考试表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userExamService.deleteUserExamByIds(ids));
    }
}
